{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1 数据准备-liepin-PM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.1 请求页面准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你要查询的职位PM\n"
     ]
    }
   ],
   "source": [
    "用户输入职位 = input(\"请输入你要查询的职位\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "城市编码 = {\n",
    "    '北京':'010',\n",
    "    '上海':'020',\n",
    "    '广州':'050020',\n",
    "    '深圳':'050090'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你想要查询的城市北京\n"
     ]
    }
   ],
   "source": [
    "用户输入城市 = 城市编码[input(\"请输入你想要查询的城市\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'requests_html'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mrequests_html\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m HTMLSession\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mjson\u001b[39;00m\n\u001b[0;32m      4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'requests_html'"
     ]
    }
   ],
   "source": [
    "import pandas\n",
    "from requests_html import HTMLSession\n",
    "import json\n",
    "import pandas as pd\n",
    "\n",
    "\n",
    "url = \"https://apic.liepin.com/api/com.liepin.searchfront4c.pc-search-job\"\n",
    "payload = {\n",
    "    \"data\": {\n",
    "        \"mainSearchPcConditionForm\": {\n",
    "            \"city\": 用户输入城市,\n",
    "            \"dq\": 用户输入城市,\n",
    "            \"pubTime\": \"\",\n",
    "            \"currentPage\": 0,\n",
    "            \"pageSize\": 40,\n",
    "            \"key\": str(用户输入职位),\n",
    "            \"suggestTag\": \"\",\n",
    "            \"workYearCode\": \"0\",\n",
    "            \"compId\": \"\",\n",
    "            \"compName\": \"\",\n",
    "            \"compTag\": \"\",\n",
    "            \"industry\": \"\",\n",
    "            \"salary\": \"\",\n",
    "            \"jobKind\": \"\",\n",
    "            \"compScale\": \"\",\n",
    "            \"compKind\": \"\",\n",
    "            \"compStage\": \"\",\n",
    "            \"eduLevel\": \"\"\n",
    "        },\n",
    "        \"passThroughForm\": {\n",
    "            \"scene\": \"input\",\n",
    "            \"skId\": \"\",\n",
    "            \"fkId\": \"\",\n",
    "            \"ckId\": \"h2c8pxojavrmo1w785z7ueih2ybfpux8\",\n",
    "            \"suggest\": None\n",
    "        }\n",
    "    }\n",
    "}\n",
    "\n",
    "# create an HTML session using Requests-HTML\n",
    "session = HTMLSession()\n",
    "\n",
    "# set the headers\n",
    "headers = {\n",
    "    'Accept': 'application/json, text/plain, */*',\n",
    "    'Accept-Encoding': 'gzip, deflate, br',\n",
    "    'Accept-Language': 'zh-CN,zh;q=0.9',\n",
    "    'Cache-Control': 'no-cache',\n",
    "    'Connection': 'keep-alive',\n",
    "    'Content-Length': '412',\n",
    "    'Content-Type': 'application/json;charset=UTF-8;',\n",
    "    'Cookie': 'inited_user=0b40e95258783b742e53b3c4507c0e74; __gc_id=ba575649f262440b97583f40312082aa; __uuid=1680367209983.58; _ga=GA1.1.1780140015.1681902728; need_bind_tel=false; new_user=false; c_flag=fd8e161021d62dd50e5032f3c60a147a; imClientId=40be7e37d455d9dca12bac537377bfad; imId=40be7e37d455d9dc3e4f5f0f695234e5; imClientId_0=40be7e37d455d9dca12bac537377bfad; imId_0=40be7e37d455d9dc3e4f5f0f695234e5; XSRF-TOKEN=p9QLPjJMQx-fu-i4zHjHkA; __tlog=1686135762104.38%7C00000000%7C00000000%7Cs_o_007%7Cs_o_007; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1683716818,1685532618,1685585264,1686135762; acw_tc=2760828a16861357626407991edc7db7268d07d91730c11cbe4406bd01776f; UniqueKey=fe87a9f3258ac642a9dba665e9526a14; liepin_login_valid=0; lt_auth=s7sPPHQMxlXw4XfcjTcLtacfj9%2BsU2yYpnhehk8FhoK5W6Ll4P%2FgSwuCq7gH%2FioIqx0mJf0zMLb2M%2Bn9zHtK6EMS%2BVGnlZ6utf6k0HsCUeZkJsW2vezHg%2FXUQp0lnEAA8nJbpEIL%2BVzO; access_system=C; user_roles=0; user_photo=5f8fa3a679c7cc70efbf444e08u.png; user_name=%E6%B2%88%E8%BF%9E%E6%9D%B0; inited_user=0b40e95258783b742e53b3c4507c0e74; imApp_0=1; fe_im_socketSequence_new_0=2_1_2; fe_im_connectJson_0=%7B%220_fe87a9f3258ac642a9dba665e9526a14%22%3A%7B%22socketConnect%22%3A%223%22%2C%22connectDomain%22%3A%22liepin.com%22%7D%7D; fe_im_opened_pages=; _ga_54YTJKWN86=GS1.1.1686135760.13.1.1686135955.0.0.0; __session_seq=4; __uv_seq=4; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1686135956',\n",
    "    'Host': 'apic.liepin.com',\n",
    "    'Origin': 'https://www.liepin.com',\n",
    "    'Pragma': 'no-cache',\n",
    "    'Referer': 'https://www.liepin.com/',\n",
    "    'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"',\n",
    "    'sec-ch-ua-mobile': '?0',\n",
    "    'sec-ch-ua-platform': '\"macOS\"',\n",
    "    'Sec-Fetch-Dest': 'empty',\n",
    "    'Sec-Fetch-Mode': 'cors',\n",
    "    'Sec-Fetch-Site': 'same-site',\n",
    "    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',\n",
    "    'X-Client-Type': 'web',\n",
    "    'X-Fscp-Bi-Stat': '{\"location\": \"https://www.liepin.com/zhaopin/?inputFrom=head_navigation&scene=init&workYearCode=1&ckId=rc7wjmfwag9eis7k995hi2xx7sjj6dpb\"}',\n",
    "    'X-Fscp-Fe-Version': '',\n",
    "    'X-Fscp-Std-Info': '{\"client_id\": \"40108\"}',\n",
    "    'X-Fscp-Trace-Id': '296c6ffc-320c-4ab2-ab90-29e44a2664d4',\n",
    "    'X-Fscp-Version': '1.1',\n",
    "    'X-Requested-With': 'XMLHttpRequest',\n",
    "    'X-XSRF-TOKEN': 'p9QLPjJMQx-fu-i4zHjHkA'\n",
    "}\n",
    "\n",
    "# send a POST request with headers\n",
    "r = session.post(url, data=json.dumps(payload), headers=headers)\n",
    "\n",
    "# extract the JSON data from the response\n",
    "response_data = r.json()\n",
    "\n",
    "# example: print the number of job postings returned\n",
    "print(response_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2 翻页获取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'response_data' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmath\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m page \u001b[38;5;241m=\u001b[39m \u001b[43mresponse_data\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdata\u001b[39m\u001b[38;5;124m'\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpagination\u001b[39m\u001b[38;5;124m'\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtotalPage\u001b[39m\u001b[38;5;124m'\u001b[39m]\n",
      "\u001b[1;31mNameError\u001b[0m: name 'response_data' is not defined"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "page = response_data['data']['pagination']['totalPage']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'response_data' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [6]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mresponse_data\u001b[49m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'response_data' is not defined"
     ]
    }
   ],
   "source": [
    "response_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'page' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [7]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[0;32m      2\u001b[0m response_df \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[43mpage\u001b[49m):\n\u001b[0;32m      4\u001b[0m     payload[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdata\u001b[39m\u001b[38;5;124m'\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmainSearchPcConditionForm\u001b[39m\u001b[38;5;124m'\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcurrentPage\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m=\u001b[39mi\n\u001b[0;32m      5\u001b[0m     \u001b[38;5;66;03m# send a POST request with headers\u001b[39;00m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'page' is not defined"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "response_df = []\n",
    "for i in range(page):\n",
    "    payload['data']['mainSearchPcConditionForm']['currentPage']=i\n",
    "    # send a POST request with headers\n",
    "    r = session.post(url, data=json.dumps(payload), headers=headers)\n",
    "\n",
    "    # extract the JSON data from the response\n",
    "    response_data = r.json()\n",
    "    df = pd.json_normalize(response_data['data']['data']['jobCardList'])\n",
    "    response_df.append(df)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "response_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.concat(response_df).reset_index()\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 数据整理成表格并加上时间戳"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "key=\"_\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "output_time = str(time.localtime().tm_mon)\\\n",
    "            +str(time.localtime().tm_mday)+''\\\n",
    "            +str(time.localtime().tm_hour)\n",
    "output_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_excel('liepin'+key+output_time+'.xlsx')\n",
    "df\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2 数据分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 改名方便看"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.1 筛选存在数据分析价值的列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_liepin_gz = df[['job.salary','job.labels','job.dq','job.requireWorkYears','job.requireEduLevel','comp.compStage','comp.compName','job.title']]\n",
    "\n",
    "df_liepin_gz"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.2 广州的PM地区分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_liepin_gz['job.dq'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "地区 = [ df_liepin_gz['job.dq'].value_counts().index.tolist()[i].split('-')[1]\n",
    "      for i,v in enumerate(df_liepin_gz['job.dq'].value_counts().index.tolist()) if '-' in v]\n",
    "地区"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "岗位个数 = [df_liepin_gz['job.dq'].value_counts().to_list()[i]\n",
    "       for i,v in enumerate(df_liepin_gz['job.dq'].value_counts().index.tolist()) if '-' in v]\n",
    "\n",
    "岗位个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    Map()\n",
    "    .add(用户输入城市, [list(z) for z in zip(地区,岗位个数)],用户输入城市)\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"Map-\"+用户输入城市+\"地图\"), visualmap_opts=opts.VisualMapOpts()\n",
    "    )\n",
    "\n",
    ")\n",
    "c.render(key+\"_dq_\"+用户输入城市+\"_地区分布_\"+output_time+ \".html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.3 职位分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "zhiwei = df_liepin_gz['job.title'].value_counts()\n",
    "zhiwei\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "zhiwei.info()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "len(zhiwei)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 词云图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 列表推导式\n",
    "word = [(df_liepin_gz['job.title'][i],zhiwei[i]) for i in range(len(zhiwei))]\n",
    "word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "words = word[0:20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "words"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import WordCloud\n",
    "from pyecharts.globals import SymbolType\n",
    "\n",
    "\n",
    "c = (\n",
    "    WordCloud()\n",
    "    .add(\"\", words, word_size_range=[20, 100], shape=SymbolType.DIAMOND)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"WordCloud-shape-diamond\"))\n",
    "    .render(\"333.html\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import WordCloud\n",
    "from pyecharts.globals import SymbolType\n",
    "\n",
    "\n",
    "words = [\n",
    "    (\"Sam S Club\", 10000),\n",
    "    (\"Macys\", 6181),\n",
    "    (\"Amy Schumer\", 4386),\n",
    "    (\"Jurassic World\", 4055),\n",
    "    (\"Charter Communications\", 2467),\n",
    "    (\"Chick Fil A\", 2244),\n",
    "    (\"Planet Fitness\", 1868),\n",
    "    (\"Pitch Perfect\", 1484),\n",
    "    (\"Express\", 1112),\n",
    "    (\"Home\", 865),\n",
    "    (\"Johnny Depp\", 847),\n",
    "    (\"Lena Dunham\", 582),\n",
    "    (\"Lewis Hamilton\", 555),\n",
    "    (\"KXAN\", 550),\n",
    "    (\"Mary Ellen Mark\", 462),\n",
    "    (\"Farrah Abraham\", 366),\n",
    "    (\"Rita Ora\", 360),\n",
    "    (\"Serena Williams\", 282),\n",
    "    (\"NCAA baseball tournament\", 273),\n",
    "    (\"Point Break\", 265),\n",
    "]\n",
    "c = (\n",
    "    WordCloud()\n",
    "    .add(\"\", words, word_size_range=[20, 100], shape=SymbolType.DIAMOND)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"WordCloud-shape-diamond\"))\n",
    "    .render(\"wordcloud_diamond.html\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.4 job.labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "biaoqian = df_liepin_gz['job.labels'].value_counts()\n",
    "biaoqian[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import WordCloud\n",
    "from pyecharts.globals import SymbolType\n",
    "\n",
    "\n",
    "words = word\n",
    "c = (\n",
    "    WordCloud()\n",
    "    .add(\"\", words, word_size_range=[20, 100], shape=SymbolType.DIAMOND)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"职位词云图\"))\n",
    "    .render(\"wordcloud_diamond.html\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.5 薪资（平均薪资）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_liepin_gz.rename(columns={'job.labels':'职位标签','job.title':'职位名称','job.salary':'薪资','job.dq':'地区','job.requireEduLevel':'学历','job.requireWorkYears':'工作年限','comp.compName':'公司名称'},inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_liepin_gz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "非薪资面议 = df_liepin_gz.query(\"薪资 != '薪资面议' and 薪资 != '面议'\")\n",
    "非薪资面议"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "非薪资面议_detail = 非薪资面议['薪资'].apply(lambda x:x.split('薪')[0].split('·')).tolist()\n",
    "非薪资面议_detail"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "平均薪资 = [ (int(i[0].split('-')[0]) +int(i[0].split('-')[1].split('k')[0]))/2    \\\n",
    " if len(i)==1 else round((int(i[0].split('-')[0]) +int(i[0].split('-')[1].split('k')[0]))/2*int(i[1])/12,1)     \\\n",
    " for i in 非薪资面议_detail        ] \n",
    "平均薪资"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "len(平均薪资)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "非薪资面议['平均薪资']=平均薪资"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分地区平均薪资\n",
    "分地区_平均薪资 = 非薪资面议.groupby('地区').agg({'平均薪资':'median'})\n",
    "分地区_平均薪资"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "分地区_平均薪资_values =  [round(i[0],1) for i in 分地区_平均薪资.values.tolist()]\n",
    "分地区_平均薪资_values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "分地区_平均薪资_index = 分地区_平均薪资.index.tolist()\n",
    "分地区_平均薪资_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "\n",
    "c = (\n",
    "    Bar()\n",
    "    .add_xaxis([i.split('-')[1] for i in 分地区_平均薪资_index[1:]])\n",
    "    .add_yaxis(\"地区\",分地区_平均薪资_values[1:])\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"PM-分地区-中位数薪资\"),\n",
    "        brush_opts=opts.BrushOpts(),\n",
    "    )\n",
    "    .render( key + \"_bar_with_brush_地区薪资中位数_\"+output_time+'.html')\n",
    ")\n",
    "# c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_year_salary = 非薪资面议.groupby('工作年限').agg({'平均薪资':'mean'})\n",
    "df_year_salary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分工作时间和学历平均薪资\n",
    "df_year_edulevel =  非薪资面议.groupby(['工作年限','学历']).agg({'平均薪资':'mean'})\n",
    "df_year_edulevel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分行业\n",
    "df_industry = 非薪资面议.groupby('行业').agg({'平均薪资':'mean'})\n",
    "df_industry"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
